package com.jx.flowershopmanager.adapter;

import android.annotation.SuppressLint;
import android.os.Build;
import android.text.Layout;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.recyclerview.widget.RecyclerView;

import com.jx.flowershopmanager.R;
import com.jx.flowershopmanager.entity.SalesRecordEntity;
import com.jx.flowershopmanager.model.SalesRecord;

import org.w3c.dom.Text;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;

public class OrderAdapter extends RecyclerView.Adapter<OrderAdapter.ViewHolder> {
    private List<SalesRecord.Data> mSalesRecordList;


    static class ViewHolder extends RecyclerView.ViewHolder {

        ImageView orderImage;
        TextView textName;
        TextView textDate;
        TextView textPrice;
        TextView textCount;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            orderImage = itemView.findViewById(R.id.order_image);
            textName = itemView.findViewById(R.id.name);
            textDate = itemView.findViewById(R.id.date);
            textPrice = itemView.findViewById(R.id.price_text);
            textCount = itemView.findViewById(R.id.count_text);
        }
    }

    public OrderAdapter(List<SalesRecord.Data> salesRecordList){
        mSalesRecordList = salesRecordList;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.order_item, parent, false);
        return new ViewHolder(view);
    }

    @RequiresApi(api = Build.VERSION_CODES.O)
    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.LONG, Locale.CHINA);

        SalesRecord.Data data = mSalesRecordList.get(position);
        holder.textName.setText(data.getFlower().getfName());
        holder.textCount.setText(String.valueOf(data.getTotal()));
        holder.textPrice.setText(String.valueOf(data.getCount()));
        holder.textDate.setText(dateFormat.format(data.sDate));
    }

    @Override
    public int getItemCount() {
        return mSalesRecordList.size();
    }


}
